package UserInterface;

interface CallBackFunction {
	void run();
}

/**
 * It is belong to screen class, and used in order to execute functions.
 */
public class Link
{
	private int x;
	private int y;
	private int width;
	private int height;
	private CallBackFunction callback;
	private boolean active;
	private boolean alwaysActive;
	

	/**
	 * Creates and abstract rectangular link which is used to call an action when the mouse clicking on it.
	 * @param a is the upper left x-coordinate of the link
	 * @param b is the upper left y-coordinate of the link
	 * @param c is the width of the link
	 * @param d is the height of the link
	 * @param e is the function which's run() method will be implement when the link is selected
	 * @param f is the boolean which determines the link is active or not
	 */
	public Link(int a,int b, int c, int d, CallBackFunction e, boolean f)
	{
		x = a;
		y = b;
		width=c;
		height=d;
		callback = e;
		active = f;
		alwaysActive = false;
	}
	
	/**
	 * Sets the link active and publish if the given x,y is inside the link area
	 */
	public void render(int x, int y)
	{
		if( (this.x <= x && x <= this.x + this.width) && (this.y <= y && y <= this.y + this.height))
			this.active = true;
		else
			this.active = false;
		publish();
		
	}
	/**
	 * Runs the given call back function
	 */
	public void publish()
	{
		this.getCallback().run();
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public CallBackFunction getCallback() {
		return callback;
	}

	public void setCallback(CallBackFunction callback) {
		this.callback = callback;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
	
	public void setAlwaysActive(boolean alwaysActive){
		this.alwaysActive = alwaysActive;
		this.active = this.alwaysActive;
	}
	public boolean isAlwaysActive(){
		return this.alwaysActive;
	}
	
	
}